package com.cooper.mediadb.online;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.cooper.scraper.DownloadException;
import com.cooper.scraper.HttpDownload;
import com.cooper.scraper.ScraperException;

public class AnalyzeDirect extends AnalyzeVideo {
	
	private String reg;
	private int group;

	public AnalyzeDirect(HttpDownload httpDownload, String url, String format,
			String reg, int group) {
		super(httpDownload, url, format);
		this.reg = reg;
		this.group = group;
	}

	@Override
	public List<String> analyzeVideo() throws DownloadException,
			ScraperException, IOException {
		List<String> result = new ArrayList<String>();
		String page = httpDownload.downloadPage(url);
		if (!Thread.currentThread().isInterrupted()) {
			Matcher m = Pattern.compile(reg).matcher(page);
			if (m.find()){
				result.add(m.group(group));
			}
		}
		return result;
	}

}
